<template>
  <v-touch class="role" @tap="roleTouch" :style="roleStyle"></v-touch>
</template>

<script>
import { mapGetters, mapActions } from "vuex"
import { mixins } from "@/common/mixins/roleMixins.js"
export default {
  mixins: [mixins],
  props: ["dialogueIndex"],
  computed: {
    ...mapGetters("wordStatus", {
      indexDialogue: "getIndexDialogue",
      dialogueSerialNumbers: "getDialogueSerialNumbers"
    })
  },
  methods: {
    //角色点击
    roleTouch: function () {
      // 当前页对话serialNumbers最大和最小值 
      const minSerialNumbers = this.MinParam(this.dialogueIndex, 'serialNumbers'),
        maxSerialNumbers = this.MaxParam(this.dialogueIndex, 'serialNumbers')
      //对话serialNumbers为最大值 则初始化对话顺序
      if (this.dialogueSerialNumbers === maxSerialNumbers) {
        this.updateDialogueSerialNumbers(0)
      }
      //对话顺序 < serialNumbers 则为第一个对话
      if (this.dialogueSerialNumbers < minSerialNumbers) {
        for (let i = 0, len = this.roleDialogue.length; i < len; i++) {
          if (this.roleDialogue[i].serialNumbers === minSerialNumbers) {
            this.touchAnima()
            this.setIndexDialogue(this.roleDialogue[i])
            this.parseTextAudio({ play: false })
            this.diologMusic({ src: this.roleDialogue[i].audioUrls }).then(() => {
              this.touchAnimaEnd()
              this.setIndexDialogue({})
            })
            break
          }
        }
      }
      //对话顺序 + 1 下一段对话
      else {
        for (let i = 0, len = this.roleDialogue.length; i < len; i++) {
          if (this.roleDialogue[i].serialNumbers === this.dialogueSerialNumbers + 1) {
            this.touchAnima()
            this.setIndexDialogue(this.roleDialogue[i])
            this.parseTextAudio({ play: false })
            this.diologMusic({ src: this.roleDialogue[i].audioUrls }).then(() => {
              this.touchAnimaEnd()
              this.setIndexDialogue({})
            })
            break
          }
        }
      }
    },
    ...mapActions("wordStatus", ["setIndexDialogue", "updateDialogueSerialNumbers"])
  }
};
</script>
    
<style scoped lang='stylus'></style>